#ifndef CSOCKMAIN_H
#define CSOCKMAIN_H

#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <fstream>//To load files
#include <queue>//Input queue
#include <cmath>

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_net.h"
#include "SDL/SDL_thread.h"

#define MAXLEN 1024


/*special characters to send data:
"/" start of message , end of message and command delimiter
"#" field delimiter
*/
 enum NetCommand
	{ //Enumerates server/client commands

    //Setup / control commands
       CREATE_NEW_ACCOUNT =1,
       LOGIN_WITH_ACCOUNT = 2,
       ACCOUNT_ACCEPTED =3,
       DUPLICATE_ACCOUNT = 4,
       UNKNOW_USERNAME = 5,
       BAD_PASSWORD = 6,
       NEW_ACCOUNT_ACCEPTED = 7,



	//Movement commands
	   SEND_UP = 101,//Key UP USE: SEND_UP
	   SEND_DOWN = 102,//Key DOWN USE: SEND_DOWN
	   SEND_LEFT = 103,//Key LEFT USE: SEND_LEFT
	   SEND_RIGHT = 104,//Key RIGHT USE: SEND_RIGHT
	   SEND_ENTER = 105,//ENTER key

    //Level Load / Game syncronism

//Data send

        SEND_SKILL = 300,
        SEND_RACE = 301,
        SEND_ITEM = 302,

	   EMPTY_COMMAND =  65535  //An empty command, USE: EMPTY_COMMAND
  	};

using namespace std;


class cSockmain
{
    public:

TCPsocket socket; //Client socket
IPaddress ip;		/* Server address */

bool Connected; //Client connected
queue<std::string> InputQueue;//Here we store received data
Uint32 UID;
std::string textmsg;
std::string LastCommand;

SDL_Thread *ListenerThread;//The network client thread
int         threadReturnValueclient;

SDL_sem *QueueInLock;


cSockmain();
virtual ~cSockmain();
void StartThreads();//start threads
static int listenerClient( void *data ); //Listener Thread
void OpenSocket(const char *ServerIp,Uint16 Port);
void ProcessMsgs(std::string Msg);

std::string intToString(int i);
void SockSend(NetCommand Command,const char* Msg);//Send Data
void CheckNewMsgs();//Displays incoming data in the input queue
};

#endif // CSOCKMAIN_H
